package com.magupe.netty.im.common.serializer.impl;

import com.alibaba.fastjson.JSON;
import com.magupe.netty.im.common.serializer.Serializer;
import com.magupe.netty.im.common.serializer.SerializerAlgorithm;

/**
 * fastjson 序列化工具
 * 
 * @author m1873
 * @since 2020-06-06
 */
public class FastJsonSerializer implements Serializer{

	/**
	 * 获取该类型序列化的标记
	 */
	@Override
	public byte getSerializerAlogrithm() {
		return SerializerAlgorithm.FASTJSON;
	}
	
	/**
	 * 序列化
	 */
	@Override
	public byte[] serialize(Object object) {
		return JSON.toJSONBytes(object);
	}

	/**
	 * 反序列化
	 */
	@Override
	public <T> T deserialize(Class<T> clazz, byte[] bytes) {
		return JSON.parseObject(bytes, clazz);
	}
}
